<?php
ob_start();

error_reporting(E_ALL);

header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"');

mb_internal_encoding('utf-8');

date_default_timezone_set('Asia/Shanghai');

$path = dirname(__FILE__).'/../';

set_include_path('.' . PATH_SEPARATOR . $path . PATH_SEPARATOR . $path . 'library/'. PATH_SEPARATOR . 
                    $path . 'application/models/' . PATH_SEPARATOR . $path. 'application/views/'. PATH_SEPARATOR . get_include_path());


include 'assembly.php';
include 'Zend/Loader.php';
include 'config/config.php';

spl_autoload_register(array('Zend_Loader', 'autoload'));
spl_autoload_register('myAutoloader');

//set locale
Utility::setLocaleInfo($path);

//prepare log
Logger::setLogPath($path.'logs/');

$config = new Zend_Config($configs);

$registry = Zend_Registry::getInstance();
$registry->set('config', $config);
$registry->set('timer', new Timer());
$registry->set('sessvc', SessionSvc::getInstance('LB'));

$db = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());

//debug sqls
$db->getProfiler()->setEnabled(false);

Zend_Db_Table::setDefaultAdapter($db);

//prepare idgenter
$ch = CacheHelper::getInstance($path);
$idgenter = IDGenter::getInstance();
$idgenter->setCacheHelper($ch);
$idgenter->setDbDriver($db);


//prepare fileuploader
FileUploader::setDir($config->img->dir);
FileUploader::setUrl($config->img->url);


$frontController = Zend_Controller_Front::getInstance();
$frontController->setBaseUrl('/');
$frontController->setControllerDirectory($path.'application/controllers');
$frontController->throwExceptions(true);

$frontController->dispatch();

$profiler = $db->getProfiler();
$res = $profiler->getQueryProfiles();
var_dump($res);
